<html>
    <head>
        <script type="text/javascript" src="/Core/jquery-1.2.6.js"></script>
        <script type="text/javascript" src="/Core/edj.js"></script>
        <link href="/Core/edj.css" type="text/css" rel="Stylesheet" />
    </head>
    <body>
        <h4>Core tests</h4>
        
        <div id="outputDiv" style="font-family:Verdana; font-size:10pt; border:1px solid gray">
        </div>        
        
        <script type="text/javascript">
            $(document).ready( function() {

            function assertInternal(expr, msg) {
                if (expr)
                    console.log("ok: " + assertInternal.caller.name);
                else
                    console.error("FAILED: " + assertInternal.caller.name);
            }


            function assertEqInternal(expected, actual) {
                if (expected === actual)
                    console.log("ok: " + assertEqInternal.caller.name);
                else
                    console.error("FAILED: " + assertEqInternal.caller.name + " -> expected: " + expected + ", actual: " + actual);
            }

            function createSuite() {
                return new SpecSuite().FindContextsStartingWith("context");
            }


            (function should_add_fixture_to_test_queue() {
                var suite = createSuite();
                suite.AddSpecs({ 
                    "fixture name": {}
                });
                assertEqInternal(1, suite.fixtureQueue.length);
            })();
            
            
            (function should_add_every_fixture_if_more_than_one_added_at_a_time() {
                var suite = createSuite();
                suite.AddSpecs({ 
                    "first fixture": {},                    
                    "second fixture": {},                    
                    "third fixture": {}
                });
                
                suite.AddSpecs({
                    "fourth fixture": {},
                    "fifth fixture": {}
                });
                
                assertEqInternal(5, suite.fixtureQueue.length);
            })();
            
            (function should_render_output_for_each_test_fixture() {
                var suite = createSuite();
                var testWasRun = false;
                
                suite.AddSpecs({
                    "When executing a test fixture": {
                        first: 5,
                        second:10,
                        
                        context: function() {
                            this.sum = this.first + this.second;
                        },
                        
                        "should show passing tests output correctly": function() {
                            verify(this.sum).is(15);
                        },
                        
                        "should show failing tests output correctly": function() {
                            verify(true).is(false);
                        }
                        
                    },
                    
                    "When executing another fixture": {
                        "should also show the output for this one": function() {
                            verify(true).is(true);
                        }
                        
                    }
                });
                
                suite.Execute();
            
                assertInternal($(".fixture", $("#outputDiv")).length == 2);
                
            })();            
           
           
           
            });
        
        </script>
    </body>
</html>


